//
//  UpdatePswVC.m
//  students
//
//  Created by 任辰东 on 2024/2/22.
//

#import "UpdatePswVC.h"
#import "RCDTextFeidView.h"
#import "RCDCornerBtn.h"
#import "MineApis.h"

@interface UpdatePswVC ()

@property (nonatomic, strong) RCDTextFeidView *oldPwsView;
@property (nonatomic, strong) RCDTextFeidView *pwsView;
@property (nonatomic, strong) RCDCornerBtn *submitBtn;

@end

@implementation UpdatePswVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"修改密码";
    
    WeakSelf
    [self.submitBtn setClickBlock:^(UIButton * _Nonnull btn) {
        StrongSelf
        [self.view endEditing:YES];
        [self updatePassword];
    }];
}

-(void)updatePassword
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"student_id"] = [GVUserDefaults standardUserDefaults].student_id;
    params[@"old_password"] = self.oldPwsView.model.content;
    params[@"new_password"] = self.pwsView.model.content;
    
    WeakSelf
    [self showLoadingHUDWithMessage:nil];
    [MineApis updatePasswordRequestWithParams:params SuccessBlock:^(NSNumber *code, NSString *msg, id responseData) {
        StrongSelf
        [self hideLoadingHUD];
        [self.navigationController popViewControllerAnimated:YES];
        
    } FailureBlock:^(NSNumber *code, NSString *msg) {
    
        StrongSelf
        [self showWarningHUDWithMessage:msg completion:NULL];
    }];
    
}

-(void)setupViews
{
    [self.bgScrollView.contentView addSubview:self.oldPwsView];
    [self.bgScrollView.contentView addSubview:self.pwsView];
    [self.bgScrollView.contentView addSubview:self.submitBtn];
}

-(void)setupLayout
{
    
    [self.oldPwsView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.equalTo(self.bgScrollView.contentView).offset(0);
        make.left.equalTo(self.bgScrollView.contentView).offset(-6);
        make.right.equalTo(self.bgScrollView.contentView);
        make.height.mas_equalTo(50);
    }];

    [self.pwsView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.oldPwsView.mas_bottom).offset(0);
        make.left.equalTo(self.bgScrollView.contentView).offset(-6);
        make.right.equalTo(self.bgScrollView.contentView);
        make.height.mas_equalTo(50);
    }];

    [self.submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.pwsView.mas_bottom).offset(40);
        make.left.equalTo(self.bgScrollView.contentView).offset(15);
        make.right.equalTo(self.bgScrollView.contentView).offset(-15);
        make.height.mas_equalTo(40);
        make.bottom.equalTo(self.bgScrollView.contentView).offset(-30 + kBottomOffset);
    }];
    
}

#pragma mark -- lazyload

-(RCDTextFeidView *)oldPwsView
{
    if (!_oldPwsView) {
        RCDTextFeidViewModel *model = [RCDTextFeidViewModel new];
        model.leftTitle = @"原密码";
        model.leftTitleFont = UIFontSize(15);
        model.leftTitleColor = UIColorFromHex(kColorTitle);
        model.placeholder = @"请输入原密码";
        model.contentFont = UIFontSize(15);
        model.contentColor = UIColorFromHex(kColorTitle);
        _oldPwsView = [[RCDTextFeidView alloc]initWithModel:model];
        [_oldPwsView addBottomLineWithEdge:UIEdgeInsetsMake(0, 15, 0, 15)];
        _oldPwsView.backgroundColor = UIColorFromHex(kColorWhite);
    }
    return _oldPwsView;
}

-(RCDTextFeidView *)pwsView
{
    if (!_pwsView) {
        RCDTextFeidViewModel *model = [RCDTextFeidViewModel new];
        model.leftTitle = @"新密码";
        model.leftTitleFont = UIFontSize(15);
        model.leftTitleColor = UIColorFromHex(kColorTitle);
        model.placeholder = @"请输入新密码";
        model.contentFont = UIFontSize(15);
        model.contentColor = UIColorFromHex(kColorTitle);
        _pwsView = [[RCDTextFeidView alloc]initWithModel:model];
        [_pwsView addBottomLine];
        _pwsView.backgroundColor = UIColorFromHex(kColorWhite);
    }
    return _pwsView;
}

-(RCDCornerBtn *)submitBtn
{
    if (!_submitBtn) {
        _submitBtn = [RCDCornerBtn new];
        [_submitBtn setTitleString:@"完成"];
        [_submitBtn setTitleFont:16];
        _submitBtn.cornerRadius = 20;
    }
    return _submitBtn;
}


@end
